Data stored in a storage device is often accessible using a block device interface. The data is typically visible and accessible to any client with access to the storage device. Operating systems or other storage clients can erase data from the storage device, format the storage device, and otherwise manipulate and change the data.
File systems typically organize data as files in a hierarchy of directories, and an index node (inode) is assigned to each of the files and to each of the directories. A file inode includes references to data blocks of user data. A directory inode includes references to data blocks that contain filenames, which may correspond to either a directory or a file, and inode numbers corresponding to the filenames.
Some B-tree-based file systems, such as Btrfs™, provide a volume clone operation that atomically creates a copy-on-write snapshot of a volume which is a hierarchy of directories and files. By cloning, the file system does not create a copy of all metadata and/or data of the volume, but uses the native efficient clone feature of the key-value store which stores all file system metadata. That is, such B-tree-based file systems can clone a volume by creating another efficient copy of the B-tree using copy-on-write (COW) B-tree. However, this approach is not available in all file systems, as there are only certain types of key-value stores backing file systems (e.g., copy-on-write B-Trees) which support the clone operation. Furthermore, merely using directory hard links (e.g., creating a clone of a file system which initially contains a hard link to the inode of the root directory of the file system) to perform a copy-on-write clone can lead to problems in certain cases.
One case in which the use of directory hard links to perform a copy-on-write clone of a file system causes problems is when a first and second file in the file system both contain hard links to the same inode. As discussed above, a hard link is a direct link to an existing inode (whereas the connection between a file or directory and a newly created inode is generally referred to as a soft link or simply a link). Because copy-on-write means that a new inode will not be created until a change is made, the copies of the first and second files in the clone of the file system will contain hard links to the original inode. If a change is made to the copy of the first file, a new inode will be generated and the hard link of the copy of the first file will be updated to point to the new inode, but the copy of the second file will still contain a hard link to the original inode. Accordingly, the copy of the second file will not point to the correct data within the clone of the file system. As such, there is a need for a reliable method of performing a copy-on-write clone in any type of file system without requiring native clone function of key-value stores.